Skip to content

fix(prettylog): close each input file after processing - #845

Open
wanghao-SunSky wants to merge 1 commit into
rs:masterfrom
wanghao-SunSky:fix/prettylog-close-input-files
Open

wanghao-SunSky wants to merge 1 commit into
rs:masterfrom
wanghao-SunSky:fix/prettylog-close-input-files

Conversation

@wanghao-SunSky

Copy link
Copy Markdown

Summary

In cmd/prettylog/prettylog.go, the file-argument loop opens each input file with os.Open(filename) and processes it, but never closes the *os.File. Passing many log files to prettylog leaks file descriptors across iterations until os.Open fails with too many open files.

Changes

  • Close reader immediately after processInput(reader, writer) returns on each iteration in cmd/prettylog/prettylog.go (covering both success and scan-error paths).
  • Add a Unix regression test in cmd/prettylog/prettylog_unix_test.go running prettylog in a subprocess with a lowered RLIMIT_NOFILE and GOGC=off to verify 48 input files are processed cleanly without exhausting file descriptors.

Verification

  • go test -race -count=1 ./cmd/prettylog
  • go test -count=1 ./... and go test -tags binary_log -count=1 ./...
  • go vet ./... and gofmt -d

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant